package com.xiaozhu.demo;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;
/**
 * Java反射机制 实例
 * @author Administrator
 *
 */

public class JavaReflectDemo2
{

	public static void main(String[] args) throws Exception
	{
		LoadProperties() ;
	}

	private static void LoadProperties() throws Exception
	{
		// 将config.properties加载为文件输入流
		InputStream is = new FileInputStream("config.properties") ;
		// 创建一个properties对象
		Properties properties = new Properties() ;
		// 将config.properties文件输入流加载进properties对象中，实例化键值对
		properties.load(is);
		// 获得键值对的值
		String className = properties.getProperty("className") ;
		// 使用反射机制实例化键值对的值
		Collection collection = (Collection) Class.forName(className).newInstance() ;
		
		ReflectPoint p1 = new ReflectPoint(3, 3) ;
		ReflectPoint p2 = new ReflectPoint(4, 4) ;
		ReflectPoint p3 = new ReflectPoint(3, 6) ;
		ReflectPoint p4 = new ReflectPoint(3, 3) ;
		
		collection.add(p1) ;
		collection.add(p2) ;
		collection.add(p3) ;
		collection.add(p4) ;
		collection.add(p1) ;
		
		System.out.println(collection.size());
	}	

}
